<?php

if (isset($_POST['begin'])) {
	$message = "TODO LIST";
	$button = "submit";
}

elseif (isset($_POST['reset']) && isset($_COOKIE['visited'])) {
	setcookie("visited", "1", mktime()-86400) or die("Could not delete cookies. Make sure cookies are enabled");
	$message = "Cookies deleted successfully. Your data has been removed";
	$button = "close";
}

elseif (!isset($_COOKIE['visited'])) {
    // if a cookie does not exist
    // set it
	setcookie("visited", "1", mktime()+86400000) or die("Could not set cookies. Make sure cookies is enabled");
	$message = "This site uses cookies to track your data. Make sure it is enabled to retain your information.";
	$button = "begin";
}

else {
	$message = "If you are unhappy with having cookies on your computer and you wish to delete your todolist saved data, click the RESET button below.";
	$button = "reset";
}
?>

<html>
<head>
<title>Todo Organisation</title>
<link href="todo-style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<p>
  <?php
if ($message == "TODO LIST") {
	?>
    Hello.

<a href="index.php">Click here to jump back to the page</a>.
<?php
}
else {
	?>
</p>
<div id="welcome-edge"><img src="images/curved-top.png" width="500" height="15" alt=""></div>
<div id="welcome">
  <h1>
    <center>
      Welcome to TODO LIST.
    </center>
  </h1>
  <div id="text-area">
  <?php
	echo $message;
	?>
</div>
    </form>
    <form action="index.php" method="post" name="reset-form" target="_self" id="reset-form">
      <?php if ($button == "reset") { ?><input type="submit" name="reset" id="reset" value="reset" /> <?php } if ($button != "close"){?>
            <input type="submit" name="begin" id="begin" value="begin" /><?php } ?>
        </form>

  </div>
</div>
<div id="welcome-edge-bottom"><img src="images/curved-top copy.png" width="500" height="15" alt=""></div>
<!-- <meta http-equiv="REFRESH" content="10;url=http://www.todo.internetimagery.com"> <!-- timer to move onto next page -->
<?php
}
?>
</body>
</html>